<?php

require_once ROOT_DIR.'models/TodoList.php';
require_once ROOT_DIR.'views/TodoListJSON.php';
require_once ROOT_DIR.'controls/RightHelper.php';

/**
 * Tries to retreive the todo list with the given id from the database and echos the resulting view
 * @param int $id
 */
function getList($id, $fullTodos = false){
	
	if(is_null($fullTodos)) $fullTodos = false;
	
	$list = TodoList::getList($id);
	if(is_null($list)){
		$res = new ResultJSON(true, session_id(), ERROR_LIST_DOES_NOT_EXIST);
		echo $res->renderView();
	} else {
		if($list->getOwnerID() == $_SESSION['USER_ID'] || $_SESSION['USER_NAME'] == 'admin' || RightHelper::sharesList($list)){
			echo TodoListJSON::getView($list, $fullTodos);
		} else {
			$res = new ResultJSON(true, session_id(), ERROR_NOT_ALLOWED);
			echo $res->renderView();
		}
	}
}

?>